<?php

class PhpFox_Mod_Video_ComponentRating extends BaseComponent
{
    function process()
    {
    	App::checkUserAccess('video', array('full', 'read_only'));

    	$aItem = $this->getParam('aItem');

    	$oSrvVideo = &$this->_oModule->getService('Video');

    	$oReq = &App::getRequest();


		if ($iRating = $oReq->get('rating'))
		{
			$oSrvVideo->addRating($aItem['vid_id'], $iRating);
		}

		$iVidRating = round($aItem['vid_rating']);
		
		$showStars = 0;
		if ( $iVidRating == 5)
		{
			$showStars = 5;
		}
		elseif ( $iVidRating == 4)
		{
			$showStars = 4;
		}
		elseif ( $iVidRating == 3)
		{
			$showStars = 3;
		}
		elseif ( $iVidRating == 2)
		{
			$showStars = 2;
		}
		elseif ( $iVidRating == 1)
		{
			$showStars = 1;
		}

		$this->oTpl->assign(array
		(
			'iId' => $aItem['vid_id'],
			'iTotal' => $aItem['vid_rating_count'],
			'actualRating' => $iVidRating,
			'showStars' => $showStars,
		));

		return $this->oTpl->fetch('Rating.html');
    }
}

?>